// CSE 142 Winter 2008, Marty Stepp // // The DrunkenFratGuys all choose a random location to have a party, // then they all move onto that location together. // Sadly, only one of them can occupy this location, so all but 1 die. import java.util.*; public class DrunkenFratGuy extends Critter { // Static fields are data that is shared by all objects of the class. // Rather than 25 frat guys having 25 copies of the data, they all can // see and change the same variables together. // // We'll use this so that they can all share information about where the "party" is. private static int randomX; private static int randomY; // shared data for party's location public DrunkenFratGuy() { // randomly pick party location Random rand = new Random(); randomX = rand.nextInt(60); randomY = rand.nextInt(50); } public Direction getMove() { // move to party location if (getY() != randomY) { return Direction.NORTH; } else if (getX() != randomX) { return Direction.EAST; } else { // I am at the party already; stay there return Direction.CENTER; } } }